home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / fgl105c.zip / CC-01.ASM < prev    next >
Assembly Source File  |  1991-05-07  |  5KB  |  114 lines

  1. ;****************************************************************************
  2. ;
  3. ; int1C -- A medium model template to define an interrupt handler for INT 1C
  4. ;          (if flag=1) or to replace the original INT 1C handler (if flag=0).
  5. ;
  6. ; Prototype:  void int1C(int flag);
  7. ;
  8. ;****************************************************************************
  9.  
  10.            EXTRN   _status1:word ; C global variable for button 1 status
  11.            EXTRN   _status2:word ; C global variable for button 2 status
  12.            EXTRN   _fg_button:far ; Fastgraph routine
  13.  
  14. int1C_TEXT SEGMENT byte public 'CODE'
  15.            ASSUME  cs:int1C_TEXT
  16.  
  17. int1C_CS   dw      ?             ; holds original INT 1C segment address
  18. int1C_IP   dw      ?             ; holds original INT 1C offset
  19. orig_DS    dw      ?             ; holds original data segment
  20.  
  21. _int1C     PROC    far
  22.            PUBLIC  _int1C
  23.  
  24.            push    bp            ; save caller's BP register
  25.            mov     bp,sp         ; make BP point to argument list
  26.            push    si            ; save caller's SI register
  27.            push    di            ; save caller's DI register
  28.  
  29.            mov     dx,[bp+6]     ; get the flag parameter
  30.            or      dx,dx         ; replace the old interrupt handler?
  31.            jz      replace       ; yes, branch to that processing
  32.  
  33. ; define a new handler for INT 1C
  34.  
  35. define:    mov     ax,ds         ; put current data segment in AX
  36.            mov     cs:orig_DS,ax ; save it in the control information area
  37.  
  38.            mov     al,1Ch        ; interrupt vector to save
  39.            mov     ah,53         ; function 53: get interrupt vector
  40.            int     21h           ; get the interrupt vector
  41.            mov     cs:int1C_CS,es; save the segment
  42.            mov     cs:int1C_IP,bx; save the offset
  43.  
  44.            push    ds            ; save our DS register
  45.            mov     dx,offset handler ; get offset of interrupt handler
  46.            mov     ax,seg handler; get segment of interrupt handler
  47.            mov     ds,ax         ; put it in DS
  48.            mov     al,1Ch        ; interrupt vector to change
  49.            mov     ah,37         ; function 37: set interrupt vector
  50.            int     21h           ; change the INT 1C vector to our handler
  51.            pop     ds            ; restore our DS register
  52.  
  53.            jmp     short return  ; return to the caller
  54.  
  55. ; replace the original handler for INT 1C
  56.  
  57. replace:   push    ds            ; save our DS register
  58.            mov     dx,cs:int1C_IP; put original INT 1C offset in DX
  59.            mov     ds,cs:int1C_CS; put original INT 1C segment in DS
  60.            mov     ah,37         ; function 37: set interrupt vector
  61.            mov     al,1Ch        ; interrupt vector 1C
  62.            int     21h           ; restore original INT 1C vector
  63.            pop     ds            ; restore our DS register
  64.  
  65. return:    xor     ax,ax         ; in case int1C was called as a function
  66.            pop     di            ; restore our DI register
  67.            pop     si            ; restore our SI register
  68.            pop     bp            ; restore our BP register
  69.            ret
  70.  
  71. _int1C     ENDP
  72.  
  73.  
  74. handler    PROC    far           ; interrupt handler that replaces INT 1C
  75.  
  76.            cli                   ; disable interrupts while handler is active
  77.            push    ax            ; save registers that may be altered
  78.            push    bx
  79.            push    cx
  80.            push    dx
  81.            push    di
  82.            push    si
  83.            push    ds
  84.            push    es
  85.  
  86.            mov     ds,cs:orig_DS ; retrieve the original data segment
  87.  
  88.            mov     ax,1          ; use joystick 1
  89.            push    ax            ; pass joystick number to button routine
  90.            call    _fg_button    ; AX = button status for joystick 1
  91.            add     sp,2          ; remove the argument
  92.            or      _status1,ax   ; update the status variable for joystick 1
  93.  
  94.            mov     ax,2          ; use joystick 2
  95.            push    ax            ; pass joystick number to button routine
  96.            call    _fg_button    ; AX = button status for joystick 2
  97.            add     sp,2          ; remove the argument
  98.            or      _status2,ax   ; update the status variable for joystick 2
  99.  
  100.            pop     es            ; restore altered registers
  101.            pop     ds
  102.            pop     si
  103.            pop     di
  104.            pop     dx
  105.            pop     cx
  106.            pop     bx
  107.            pop     ax
  108.            iret                  ; return from the interrupt routine
  109.  
  110. handler    ENDP
  111.  
  112. int1C_TEXT ENDS
  113.            END
  114.